package com.example.testhiber.initPackage.config.model.dao;

import com.example.testhiber.initPackage.config.model.entity.BaseEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.QueryHint;
import java.io.Serializable;
import java.util.List;

/**
 * The Interface Dao.
 *
 * @param <K> the key type
 * @param <M> the generic type
 */
@NoRepositoryBean
public interface Dao<K extends Serializable, M extends BaseEntity<K>>
extends
        JpaSpecificationExecutor<M>, JpaRepository<M,K> {

	// save
	/* (non-Javadoc)
	 * @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findAll(org.springframework.data.jpa.domain.Specification, org.springframework.data.domain.Pageable)
	 */
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public Page<M> findAll(Specification<M> spec, Pageable pageable);

	/* (non-Javadoc)
	 * @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findAll(org.springframework.data.jpa.domain.Specification, org.springframework.data.domain.Sort)
	 */
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public List<M> findAll(Specification<M> spec, Sort sort);

	/* (non-Javadoc)
	 * @see org.springframework.data.jpa.repository.JpaRepository#findAll()
	 */
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public List<M> findAll();

	
}